﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="Language.cs" company="WordSteps.com">
//   All rights reserved
// </copyright>
// <summary>
//   Defines the Language type.
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace RapidDict.Infrastructure.Models
{
    using System.Collections.Generic;

    public class Language
    {
        public static readonly Language English = new Language("en", "English");
        public static readonly Language French = new Language("fr", "French");
        public static readonly Language Russian = new Language("ru", "Russian");
        public static readonly Language Spanish = new Language("es", "Spanish");
        public static readonly Language Chinese = new Language("zh-CN", "Chinese");
        public static readonly Language German = new Language("de", "German");
        public static readonly Language Japanese = new Language("ja", "Japanese");
        public static readonly Language Italian = new Language("it", "Italian");
        public static readonly Language Portuguese = new Language("pt", "Portuguese");

        public Language(string code, string name)
        {
            this.Code = code;
            this.Name = name;
        }

        public Language(string name)
        {
            this.Code = GetCodeBy(name);
            this.Name = name;
        }

        public string Name { get; private set; }

        /// <summary>
        /// Language code by full code notation (for example, zh-CN)
        /// </summary>
        public string Code { get; private set; }

        public static List<Language> GetLanguagesList()
        {
            var languages = new List<Language>
                               {
                                   Language.English,
                                   Language.French,
                                   Language.Russian,
                                   Language.Spanish,
                                   Language.Chinese,
                                   Language.German,
                                   Language.Japanese,
                                   Language.Italian,
                                   Language.Portuguese
                               };

            return languages;
        }

        public static string GetCodeBy(string name)
        {
            switch (name)
            {
                case "English":
                    return "en";
                case "French":
                    return "fr";
                case "Russian":
                    return "ru";
                case "Spanish":
                    return "es";
                case "Chinese":
                    return "zh-CN";
                case "German":
                    return "de";
                case "Japanese":
                    return "ja";
                case "Italian":
                    return "it";
                case "Portuguese":
                    return "pt";
            }

            return "en";
        }

        public static string GetTwoDigitCodeBy(string code)
        {
            if (code.Length > 2)
            {
                return code.Remove(2);
            }

            return code;
        }
    }
}

